import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import UnoCSS from 'unocss/vite'
import Layouts from 'vite-plugin-vue-layouts';
import VueRouter from 'unplugin-vue-router/vite'
import vueDevTools from 'vite-plugin-vue-devtools'
import Components from 'unplugin-vue-components/vite'
import AutoImport from 'unplugin-auto-import/vite'
// import Oxc from 'unplugin-oxc/rolldown'
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
import { VueAmazingUIResolver } from 'vue-amazing-ui'
// import sonda from 'sonda/rolldown'
import path from "node:path"

// https://vite.dev/config/
export default defineConfig({
  resolve:{
    alias: {
      "@/": path.join(__dirname, "./src")+"/",
    },
  },
  server:{
    port: 5800,
    hmr: true,
  },
  plugins: [
    vue(),
    Layouts({
      layoutsDirs: 'src/layout',
      pagesDirs: 'src/views',
      defaultLayout: 'layout-default'
    }),
    VueRouter({
      routesFolder: [
        {
            src: 'src/views',
            path: '',
            // override globals
            // exclude: (excluded) => excluded,
            // filePatterns: (filePatterns) => filePatterns,
            // extensions: (extensions) => extensions,
        },
      ],
      extensions: ['.vue'],
      filePatterns: ['**/*'],
      dts: 'src/typings/typed-router.d.ts',
    }),
    AutoImport({
      imports: [
        'vue',
        'vue-router',
      ],
      dts: 'src/typings/auto-imports.d.ts',
    }),
    Components({
      dts: 'src/typings/components.d.ts',
      dirs:["src/components/**"],
      types: [{ from: 'vue-router', names: ['RouterLink', 'RouterView'] }],
      resolvers: [
          AntDesignVueResolver({
              importStyle: 'css-in-js'
          }),
          // auto import components from VueAmazingUI
          VueAmazingUIResolver({
              cjs: false // whether use commonjs build, default false
          }),
      ]
    }),
    UnoCSS(),
    vueDevTools(),
    // legacy({
    //     targets: ['defaults', 'not IE 11'],
    // }),
    // sonda({
    //   filename: "dist/report.html",
    //   gzip: true,
    //   brotli: true
    // })
  ],
  build:{
      sourcemap: false
  }
})
